#
#   Python GUI - Alert base class - Generic
#

from ModalDialogs import ModalDialog
from Labels import Label
from Exceptions import Cancel


class BaseAlert(ModalDialog):

    yes_button = None
    no_button = None
    other_button = None

    def __init__(self, kind, prompt, width = None, lines = None,
            button_labels = None, default = None, cancel = None):
        if width is None:
            width = self._default_width
        if lines is None:
            lines = self._default_lines
        ModalDialog.__init__(self, width = width)
        self.label = Label(text = prompt, lines = lines)
        self.create_buttons(*button_labels)
        self.default_button = self._find_button(default)
        self.cancel_button = self._find_button(cancel)
        self.layout(kind)
    
    def _find_button(self, value):
        #print "BaseAlert._find_button:", value ###
        if value == 1:
            result = self.yes_button
        elif value == 0:
            result = self.no_button
        elif value == -1:
            result = self.other_button
        else:
            result = None
        #print "BaseAlert._find_button: result =", result ###
        return result
    
    def yes(self):
        self.dismiss(1)
    
    def no(self):
        self.dismiss(0)
    
    def other(self):
        self.dismiss(-1)



